<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"  %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <base href="<%=basePath%>">
    <title></title>
    <meta http-equiv="cache-control" content="no-cache">
    <link rel="stylesheet" type="text/css" href="css/maintable.css" >

    <script type="text/javascript" src="js/jquery-1.8.0.js"></script>
    <script>
        function show(pageIndex){
            window.location.href="AdminServlet?flag=manager&pageIndex="+pageIndex;
        }
        $(function (){
           $(".delete").click(function (){
               if(confirm("确认要删除吗？")){
                   var id = $(this).data("id");
                   $.ajax({
                       url:"AdminServlet",
                       data:{flag:"delete",id:id},
                       success:function (data){
                           if(data==1){
                               alert("删除成功");
                               window.location.href="AdminServlet?flag=manager"
                           }else{
                               alert("出现未知错误！");
                           }
                       }
                   });
               }
           });

           $("#ch_checkall,#top_ch_checkall").click(function (){
                $("input[name=ck_id]").attr("checked",this.checked);
           });
        });

            function deleteChecked(){
               if($("input[name=ck_id]:checked").length==0){
                   alert("请勾选至少一个！");
               }else{
                   if(confirm("确认要删除吗？")){
                       document.form1.submit();
                   }
               }
            }
    </script>
</head>

<body>
    <div class ="div_title">
        <div class="div_titlename"> <img src="/images/san_jiao.gif" ><span>管理人员基本信息列表</span></div>
        <div class="div_titleoper">
            <input type="checkbox" id="top_ch_checkall"/> 全选 <a href="/admin/admin_add.jsp"> <img src="/images/add.gif"/>添加 </a> <a href="javascript:deleteChecked()"><img src="/images/del.gif"/>删除</a> </div>
    </div>

    <form action="AdminServlet"  name="form1">
        <input name="flag" value="deleteChecked" type="hidden">

        <table class="main_table" >
            <tr>
                <th><input type="checkbox" id="ch_checkall" /></th>	<th>账号</th> 	<th>状态</th>	<th>备注</th>  <th>最后更新日期</th> 	<th>操作</th>
            </tr>
            <c:forEach items="${adminList}" var="a">
                <tr>
                    <td>
                        <input type="checkbox" name="ck_id" value="${a.id}" id="id"/>
                    </td>
                    <td>${a.adminName}</td>
                    <td>
                        <c:if test="${a.state=='1'}">
                            正常
                        </c:if>
                        <c:if test="${a.state=='2'}">
                            锁定
                        </c:if>
                    </td>
                    <td> <a title="${a.note}">${a.shortNote}</a> </td>
                    <td>
                        <fmt:formatDate value="${a.editDate }"  pattern="yyy-MM-dd HH:mm"/>
                    </td>
                    <td>
                        <c:if test="${a.state=='1'}">
                            <a href="AdminServlet?flag=stateNow&id=${a.id}&state=${a.state}" onclick=" return confirm('确认要锁定吗')" >锁定</a>
                        </c:if>
                        <c:if test="${a.state=='2'}">
                            <a href="AdminServlet?flag=stateNow&id=${a.id}&state=${a.state}" onclick=" return confirm('确认要解锁吗')">解锁</a>
                        </c:if>
                        <a href="AdminServlet?flag=update&id=${a.id}">修改</a>
                        <a href="javascript:void(0)" data-id="${a.id}" class="delete">删除</a>

                    </td>
                </tr>

            </c:forEach>
        </table>
    </form>

    <div class="div_page" >
            <div class="div_page_left">    共有 <label>${page.rowCount}</label> 条记录，当前第 <label>${page.pageIndex}</label> 页，共 <label>${page.pageCount}</label> 页	</div>
        <div class="div_page_right" >

            <c:choose>
                <c:when test="${page.hasPre }">
                    <button onclick="show(1)"> 首页</button>
                    <button onclick="show(${page.pageIndex-1})"> 上一页</button>
                </c:when>
                <c:otherwise>
                    首页
                    上一页
                </c:otherwise>
            </c:choose>

            <c:choose>
                <c:when test="${page.hasNext }">
                    <button onclick="show(${page.pageIndex+1})">  下一页 </button>
                    <button onclick="show(${page.pageCount})"> 尾页</button>
                </c:when>
                <c:otherwise>
                    下一页
                    尾页
                </c:otherwise>
            </c:choose>


            <button onclick="show(document.getElementById('pageIndex').value)">转到</button>
            <input type="text" name="pageIndex" id="pageIndex" value="${page.pageIndex }" /> 页

        </div>

    </div>
</body>
</html>